#pragma once
#include "tinyxml\tinyxml.h"
#include <Windows.h>
#include <io.h>
#include <stdio.h>
#include <tchar.h>
#include <string>
#include <vector>
using namespace std;

#define CC_SAFE_DELETE(p)			do { if(p) { delete (p); (p) = 0; } } while(0)
#define CC_SAFE_DELETE_ARRAY(p)		do { if(p) { delete[] (p); (p) = 0; } } while(0)

typedef std::vector<std::string> MP;

#ifdef _DEBUG
#define DLOG(fmt,...)	printf("[%s](%d) ==> "##fmt"\n",__FUNCTION__,__LINE__,##__VA_ARGS__);
#else
#define DLOG(fmt,...)
#endif

//#define DEBUG_PRINT_XML

class XMLParser
{
public:
	XMLParser();
	virtual ~XMLParser();
public:
	string UnicodeToUtf8(const wchar_t* buf);
	wstring Utf8ToUnicode(const char* buf);
	string XMLParser::U2G(const char* buf);
	string XMLParser::G2U(const char* buf);

	bool ReloadFromFile(const char *pFilePath,void *pPolicyData);
	bool ReloadFromFolder(const char *pFolder);
	bool SaveToFile(const char *xmlPath);
	void ReleaseXML();
private:
	virtual bool OnReloadPolicyFromFolder(const char *pFilePath)=0;
	virtual void ReadNode(TiXmlNode* pNode,void *pPolicyData,void *pRoundData=0)=0;
	virtual void WriteNode(const char *xmlPath)=0;
protected:
	int Split(char *sp,char *src,MP *ptr,int SplitCount=0);
protected:
	TiXmlDocument *xmlDoc;
	TiXmlElement* rootElement;
};